var arrLeftMenuContent = Array();
function leftMenuDrop(id) {
    if (typeof (arrLeftMenuContent[id]) != "undefined") return arrLeftMenuContent[id];
    arrTemp = m[id];
    if (typeof (arrTemp) == "undefined") return;
    str = '<div class="left_menu_drop">';
    for (i = 0; i < arrTemp.length; i++) {
        str = str + '<div class="' + (i < (arrTemp.length - 1) ? 'row  clearfix' : 'row no-bor clearfix') + '">'; 
        r = arrTemp[i].r.split("|");
        str = str + '<div class="root"><a href="/category/index?cat_id=' + r[0] + '">' + r[1] + '</a></div>';
        if (r[2] > 0) {
            str = str + '<div class="sub">';
            arrS = arrTemp[i].s;
            for (j = 0; j < arrS.length; j++) {
                s = arrS[j].split("|");
                str = str + '<a href="/category/index?cat_id=' + s[0] + '">' + s[1] + '</a>';
                if (j < (arrS.length - 1)) str = str + '<span> &nbsp; |&nbsp;</span> ';
            }
            if (r[2] > arrS.length) str = str + '<span> &nbsp; | &nbsp;</span> <a class="view-all" href="/category/index?cat_id=' + r[0] + '">Xem tất cả</a>';
            str = str + '</div>';
        }
        str = str + '</div>';
    }
    str = str + '</div>';
    arrLeftMenuContent[id] = str;
    return str;
}
function resetLeftMenuDrop() {
    resetHeaderBar();
    $(".left li").removeClass("drop_current");
}
function showLeftMenuDrop(domEle, content) {
    domEle.addClass("drop_current");
    ob = $(content);
    $("body").append(ob).append('<div class="left_menu_drop_sep"></div>');
    if (ob.find(".sub").length == 0) ob.addClass("left_menu_drop_fix");
    offsetTop = domEle.offset().top;
    offsetLeft = domEle.offset().left + domEle.outerWidth(true) - 1;
    tempH = $(window).height() - (offsetTop - $(window).scrollTop());
    if (($(window).height() - $("#user_taskbar").height()) < ob.outerHeight(true)) offsetTop = $(window).scrollTop() + $("#user_taskbar").height();
    else if (tempH < ob.outerHeight(true)) offsetTop = offsetTop + (tempH - ob.outerHeight(true));
    $(".left_menu_drop_sep").css({
        top: domEle.offset().top + 2,
        left: offsetLeft
    });
    ob.css({
        top: offsetTop,
        left: offsetLeft
    });
}
function initLeftMenuDrop() {
    $(function () {
        $(".left li").mouseenter(function () {
            resetLeftMenuDrop();            
            id = $(this).attr("iData");
            content = leftMenuDrop(id);
            showLeftMenuDrop($(this), content);
        });
    });
}
$(function () {
    $("#header,#flash,#main_body, div:not(.left), #container_footer").mouseenter(function () {
         resetLeftMenuDrop();
    });      
});
